<template>
	<view class="content">
		<view class="uni-list">
			<navigator
				:url="'newsDetail?newsId=' + item.newsId"
				class="uni-list-cell"
				v-for="(item, index) in listArr"
				:key="index"
			>
				<view class="uni-list-cell-navigate uni-navigate-right">
					{{ item.newsTitle }}
				</view>
			</navigator>
		</view>
		<uni-load-more :status="isMore"></uni-load-more>
	</view>
</template>

<script>
import uniLoadMore from '@/components/uni-load-more.vue';
import { mapState } from 'vuex';
export default {
	components: { uniLoadMore },
	computed: mapState(['URL']),
	onLoad() {
		this.getList();
	},
	onReachBottom() {
		if (this.isLa) {
			this.getList();
		}
	},
	onPullDownRefresh() {
		console.log(111);
		if (this.isXiaLa) {
			this.isXiaLa = false;
			this.isLa = true;
			this.isMore = 'more';
			this.reqData = {
				page: 0,
				rows: 20
			};
			this.listArr = [];
			this.getList();
		}else{
			// uni.showToast({
			// 	icon:'none',
			// 	title:'下拉太过频繁'
			// })
			uni.stopPullDownRefresh();
		}
	},
	data() {
		return {
			isLa: true,
			isMore: 'more',
			reqData: {
				page: 0,
				rows: 20
			},
			listArr: []
		};
	},
	methods: {
		getList() {
			this.isMore = 'loading';
			this.reqData.page++;
			uni.request({
				url: this.URL + '/news/getNewsList',
				data: this.reqData,
				success: res => {
					uni.stopPullDownRefresh();
					setTimeout(()=>{
						this.isXiaLa = true;
					},3000)
					console.log(res.data);
					this.listArr = [...this.listArr,...res.data.data];
					if(res.data.data.length !== this.reqData.rows){
						this.isMore = 'noMore'
						this.isLa = false;
					}
				}
			});
		}
	}
};
</script>

<style lang="scss"></style>
